package com.apes.fa.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.account.model.InventoryBatch;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.product.model.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.scm.stock.transfer.model
 * @ClassName: InventoryTransferAssetItem
 * @Author: pyb
 * @Description: 库存转资产明细
 * @CreateTime: 2021-04-23 15:38
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = InventoryTransferAssetItem.CONST_TABLE_NAME)
public class InventoryTransferAssetItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "inventory_asset_item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "库存转资产明细")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "transfer_asset_id", referencedColumnName = "id")
    private InventoryTransferAsset inventoryTransferAsset;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "batch_code", referencedColumnName = "id")
    @Comment("商品批次内码")
    private InventoryBatch inventoryBatch;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom uom;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id", nullable = false)
    @Comment("税率")
    private Tax tax;

    @Column(name = "price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("单价")
    private double priceUnit = 0;

    @Column(name = "product_sum_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("商品总数（可用数量）")
    private double productSumQty = 0;

    @Column(name = "product_transfer_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("可转资产数量")
    private double productTransferQty = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_category_id", referencedColumnName = "id")
    @Comment("资产类别")
    private FaCategory faCategory;

    @Column(name = "note", length = 250)
    @Comment("备注")
    private String note;

}
